//2009/08/31 02:09:49
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <sstream>
#include <algorithm>

using namespace std;

class SimpleWordGame
{
public:
    int points(vector <string> player, vector <string> dictionary)
    {
		set<string> v(player.begin(), player.end());
		set<string>::iterator it;
		int score = 0;
		for(it=v.begin(); it!=v.end(); it++)
		{
			bool flag = false;
			for(int j=0; j<dictionary.size(); j++)
			if(*it == dictionary[j]) flag = true;
			if(flag) score += (*it).size() * (*it).size();
		}
		return score;
    }
};
